<!DOCTYPE html>
<#assign ctx=request.contextPath />
<html>
<head>
<link rel="stylesheet" href="${ctx}/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${ctx}/codemirror/codemirror.css">
<script src="${ctx}/codemirror/codemirror.js"></script>
<script src="${ctx}/codemirror/clike.js"></script>

<link rel="stylesheet" href="${ctx}/codemirror/eclipse.css">
<link rel="stylesheet" href="${ctx}/codemirror/seti.css">
<link rel="stylesheet" href="${ctx}/codemirror/dracula.css">

<link rel="stylesheet" href="${ctx}/codemirror/dialog.css">
<script src="${ctx}/codemirror/vim.js"></script>
<script src="${ctx}/codemirror/searchcursor.js"></script>
<script src="${ctx}/codemirror/dialog.js"></script>

<link rel="stylesheet" href="${ctx}/codemirror/foldgutter.css"/>
<script src="${ctx}/codemirror/foldcode.js"></script>
<script src="${ctx}/codemirror/foldgutter.js"></script>
<script src="${ctx}/codemirror/brace-fold.js"></script>
<script src="${ctx}/codemirror//comment-fold.js"></script>

<link rel="stylesheet" href="${ctx}/codemirror/fullscreen.css">
<script src="${ctx}/codemirror/fullscreen.js"></script>

<script src="${ctx}/codemirror/matchbrackets.js"></script>

<link rel="stylesheet" href="${ctx}/codemirror/show-hint.css">
<script src="${ctx}/codemirror/show-hint.js"></script>
<script src="${ctx}/codemirror/anyword-hint.js"></script>
</head>
<body>
<input type="hidden" id="codeId" value="${id}"/>
<div class="container">
	<div class="row">
		<textarea id="code"><#if context??>${context}</#if></textarea>
	</div>
</div>
</body>
<script src="${ctx}/jquery/jquery.min.js"></script>
<script src="${ctx}/bootstrap/js/bootstrap.min.js"></script>
<script src="${ctx}/layer/layer.js"></script>
<script type="text/javascript">
var editor = CodeMirror.fromTextArea(document.getElementById("code"),{
			            mode:"text/x-java", 
						lineNumbers:true,
						theme:"seti",
					    fullScreen:true,
					    matchBrackets:true,
					    extraKeys:{
					    	"Alt-/":"autocomplete",
					    	"Ctrl-S":function() {
					    		layer.confirm('确认保存吗？', {
							        icon : 3,
							        title : '保存提示'
							    }, function(index, layero) {
							        $.ajax({
							            type : "editCode",
							            url :  "${ctx}/code/" + $("#codeId").val() + "/edit",
							            data :  editor.getValue(),
							            dataType : "json",
							            success : function(data) {
							                if (data.status=="1") {
							                    layer.msg(data.message, {icon : 1}, function() {
							                    	var index = parent.layer.getFrameIndex(window.name);
							   						parent.layer.close(index);
							                    });
							                } else {
							                    layer.msg(data.message, {icon : 0});
							                }
							            },
							            error : function(errorMsg) {
							                layer.msg('服务器未响应,请稍后再试', {icon : 3});
							            }
							        });
							    });
					    	}
					    }						
			   });
</script>
</html>